package controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.databind.ObjectMapper;

import biz.MissionBiz;
import biz.TeamManagerBiz;
import biz.UserBiz;
import pojo.PageTeams;
import pojo.Projects;
import pojo.Teams;
import pojo.UserRoleProject;
import pojo.UserTeam;
import pojo.Users;
import pojo.view.TeamUser;

@Controller
public class TeamManagerController {
	@Resource(name = "teamManagerBiz")
	private TeamManagerBiz teamManagerBiz;
	@Resource(name = "userBiz")
	private UserBiz userBiz;
	@Resource(name="missionBiz")
	private MissionBiz missionBiz;

	@RequestMapping("gotoTeamDetail.do")
	public String gotoTeamDetail(int teamid, HttpServletRequest request, HttpSession session) {

		// 下面四行登录联通之后删掉
		/*
		 * Users currentUser1=new Users(); currentUser1.setUserId(1);
		 * currentUser1.setUserName("李四"); session.setAttribute("currentUser",
		 * currentUser1);
		 */

		Users currentUser = (Users) session.getAttribute("currentUser");
		// 假定userid为1的用户登录
		System.out.println("在teamcontroller里的currentUser是" + currentUser.getUserName());

		int applyNowNo = 1;
		int applyTotalNo = teamManagerBiz.getApplyTotalNo(teamid);
		int teamUserNowNo = 1;
		int teamUserTotalNo = teamManagerBiz.getTeamUserTotalNo(teamid);

		// 团队创建人
		List<Map<String, String>> createUser = teamManagerBiz.getCreateUserByTeamid(teamid);
		String createUserName = null;
		if (createUser != null) {
			createUserName = createUser.get(0).get("username");
		}
		// 切换团队
		List<Map<String, String>> allTeam = teamManagerBiz.getAllTeamByUserid(currentUser.getUserId());

		// 申请加入团队模块
		List<Map<String, String>> applyPartList = teamManagerBiz.getPartApplyUsersByTeamid(teamid);
		List<Map<String, String>> applyAllList = teamManagerBiz.getPart2ApplyUsersByTeamid(teamid);
		List<Map<String, String>> listsize = teamManagerBiz.getApplyUsers1ByTeamid(teamid);
		if (listsize != null) {
			request.setAttribute("applyPartListSize", listsize.size());

		}

		// 团队成员模块
		List<Users> tempTeamUserList = teamManagerBiz.getPartTeamUserByTeamid(teamid);
		List<TeamUser> teamUserList = new ArrayList<>();
		if (tempTeamUserList != null) {
			for (int i = 0; i < tempTeamUserList.size(); i++) {
				Users user = tempTeamUserList.get(i);
				TeamUser tu = new TeamUser();
				tu.setUserId(user.getUserId());
				tu.setUserName(user.getUserName());
				tu.setEmail(user.getEmail());
				tu.setTel(user.getTel());
				tu.setHeadimage(user.getHeadimage());
				 DecimalFormat df = new DecimalFormat("#.00"); 
				tu.setTeamScore(df.format(missionBiz.findMemberScore(String.valueOf(teamid), String.valueOf(user.getUserId()))));
				// 这里还需要加团队分数
				//
				//
				//
				tu.setTeamUserNowNo(teamUserNowNo);
				tu.setTeamUserTotalNo(teamUserTotalNo);
				teamUserList.add(tu);
			}
		}

		request.setAttribute("nowteamid", teamid);
		request.setAttribute("applyNowNo", applyNowNo);
		request.setAttribute("applyTotalNo", applyTotalNo);
		request.setAttribute("applyPartList", applyPartList);
		request.setAttribute("applyAllList", applyAllList);

		request.setAttribute("createUserName", createUserName);

		request.setAttribute("allTeam", allTeam);

		request.setAttribute("teamUserList", teamUserList);
		request.setAttribute("teamUserNowNo", teamUserNowNo);
		request.setAttribute("teamUserTotalNo", teamUserTotalNo);

		return "teamdetail";
	}

	@RequestMapping("passAppluUser.do")
	public String passAppluUser(int applyUserid, int teamid) {

		int a = teamManagerBiz.updateUserTeamIsAccepted(applyUserid, teamid);
		if (a > 0) {
			return "redirect:/gotoTeamDetail.do?teamid=" + teamid;
		} else {
			return "error";
		}
	}

	@RequestMapping("appluUserFenYe.do")
	public String appluUserFenYe(int teamid, int applyNowNo, HttpServletRequest request, HttpSession session) {
		// 假定userid为1的用户登录
		Users currentUser = (Users) session.getAttribute("currentUser");
		int teamUserNowNo = 1;// 这是是不是改成currentUser.getUserId();
		int teamUserTotalNo = teamManagerBiz.getTeamUserTotalNo(teamid);

		// 申请加入团队模块
		int applyTotalNo = teamManagerBiz.getApplyTotalNo(teamid);
		List<Map<String, String>> applyPartList = teamManagerBiz.getPartApplyUsersByTeamid(teamid);
		List<Map<String, String>> applyAllList = teamManagerBiz.appluUserFenYeNext(applyNowNo, teamid);

		List<Map<String, String>> listsize = teamManagerBiz.getApplyUsers1ByTeamid(teamid);
		if (listsize != null) {
			request.setAttribute("applyPartListSize", listsize.size());

		}
		// 团队创建人
		List<Map<String, String>> createUser = teamManagerBiz.getCreateUserByTeamid(teamid);
		String createUserName = null;
		if (createUser != null) {
			createUserName = createUser.get(0).get("username");
		}
		// 切换团队
		List<Map<String, String>> allTeam = teamManagerBiz.getAllTeamByUserid(currentUser.getUserId());

		// 团队成员模块
		List<Users> tempTeamUserList = teamManagerBiz.getPartTeamUserByTeamid(teamid);
		List<TeamUser> teamUserList = new ArrayList<>();
		if (tempTeamUserList != null) {
			for (int i = 0; i < tempTeamUserList.size(); i++) {
				Users user = tempTeamUserList.get(i);
				TeamUser tu = new TeamUser();
				tu.setUserId(user.getUserId());
				tu.setUserName(user.getUserName());
				tu.setEmail(user.getEmail());
				tu.setTel(user.getTel());
				tu.setHeadimage(user.getHeadimage());
				 DecimalFormat df = new DecimalFormat("#.00"); 
					tu.setTeamScore(df.format(missionBiz.findMemberScore(String.valueOf(teamid), String.valueOf(user.getUserId()))));
					tu.setTeamUserNowNo(teamUserNowNo);
				tu.setTeamUserTotalNo(teamUserTotalNo);
				teamUserList.add(tu);
			}
		}

		request.setAttribute("nowteamid", teamid);
		request.setAttribute("applyNowNo", applyNowNo);
		request.setAttribute("applyTotalNo", applyTotalNo);
		request.setAttribute("applyPartList", applyPartList);
		request.setAttribute("applyAllList", applyAllList);

		request.setAttribute("createUserName", createUserName);

		request.setAttribute("allTeam", allTeam);

		request.setAttribute("teamUserList", teamUserList);
		request.setAttribute("teamUserNowNo", teamUserNowNo);
		request.setAttribute("teamUserTotalNo", teamUserTotalNo);

		return "teamdetail";
	}

	@ResponseBody
	@RequestMapping("deleteTeamMember.do")
	public void deleteTeamMember(int userid, int teamid, int teamUserNowNo, HttpServletResponse response) {

		response.setCharacterEncoding("UTF-8");
		// 删除团队成员模块
		int a = teamManagerBiz.deleteTeamMember(userid, teamid);

		int teamUserTotalNo = teamManagerBiz.getTeamUserTotalNo(teamid);

		// 团队成员模块
		List<Users> tempTeamUserList = teamManagerBiz.teamUserFenYe(teamUserNowNo, teamid);
		List<TeamUser> teamUserList = new ArrayList<>();
		if (tempTeamUserList != null) {
			for (int i = 0; i < tempTeamUserList.size(); i++) {
				Users user = tempTeamUserList.get(i);
				TeamUser tu = new TeamUser();
				tu.setUserId(user.getUserId());
				tu.setUserName(user.getUserName());
				tu.setEmail(user.getEmail());
				tu.setTel(user.getTel());
				tu.setHeadimage(user.getHeadimage());
				 DecimalFormat df = new DecimalFormat("#.00"); 
					tu.setTeamScore(df.format(missionBiz.findMemberScore(String.valueOf(teamid), String.valueOf(user.getUserId()))));
					// 这里还需要加团队分数
				//
				//
				//
				tu.setTeamUserNowNo(teamUserNowNo);
				tu.setTeamUserTotalNo(teamUserTotalNo);
				teamUserList.add(tu);
			}
		}

		PrintWriter out = null;
		try {
			out = response.getWriter();
			ObjectMapper mapper = new ObjectMapper();
			String data = mapper.writeValueAsString(teamUserList);

			out.println(data);

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		out.close();

	}

	@RequestMapping("teamUserFenYe.do")
	public void teamUserFenYe(int teamid, int teamUserNowNo, HttpServletResponse response) {
		response.setCharacterEncoding("UTF-8");

		int teamUserTotalNo = teamManagerBiz.getTeamUserTotalNo(teamid);

		// 团队成员模块
		List<Users> tempTeamUserList = teamManagerBiz.teamUserFenYe(teamUserNowNo, teamid);
		List<TeamUser> teamUserList = new ArrayList<>();
		if (tempTeamUserList != null) {
			for (int i = 0; i < tempTeamUserList.size(); i++) {
				Users user = tempTeamUserList.get(i);
				TeamUser tu = new TeamUser();
				tu.setUserId(user.getUserId());
				tu.setUserName(user.getUserName());

				tu.setEmail(user.getEmail());
				tu.setTel(user.getTel());
				tu.setHeadimage(user.getHeadimage());
				 DecimalFormat df = new DecimalFormat("#.00"); 
					tu.setTeamScore(df.format(missionBiz.findMemberScore(String.valueOf(teamid), String.valueOf(user.getUserId()))));
					System.out.println("fenshu"+missionBiz.findMemberScore(String.valueOf(teamid), String.valueOf(user.getUserId())));
				tu.setTeamUserNowNo(teamUserNowNo);
				tu.setTeamUserTotalNo(teamUserTotalNo);
				teamUserList.add(tu);
			}
		}

		PrintWriter out = null;
		try {
			out = response.getWriter();
			ObjectMapper mapper = new ObjectMapper();
			String data = mapper.writeValueAsString(teamUserList);

			out.println(data);

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		out.close();
	}

	@RequestMapping("gotoProjectList.do")
	public String gotoProjectList(int teamid, HttpServletRequest request, HttpSession session) {
		Users currentUser = (Users) session.getAttribute("currentUser");
		// 切换团队
		List<Map<String, String>> allTeam = teamManagerBiz.getAllTeamByUserid(currentUser.getUserId());
		// 申请加入团队模块
		List<Map<String, String>> applyPartList = teamManagerBiz.getPartApplyUsersByTeamid(teamid);
		List<Map<String, String>> listsize = teamManagerBiz.getApplyUsers1ByTeamid(teamid);
		if (listsize != null) {
			request.setAttribute("applyPartListSize", listsize.size());

		}

		// 项目
		List<Projects> projectsList = teamManagerBiz.getAllProjectsByTeamid(teamid);

		request.setAttribute("allTeam", allTeam);
		request.setAttribute("nowteamid", teamid);
		request.setAttribute("applyPartList", applyPartList);
		request.setAttribute("projectsList", projectsList);
		return "projectlist";
	}

	@RequestMapping("addProject.do")
	public void addProject(String projectName, String description, int managerSelect, String arr, int teamid,
			HttpServletResponse response, HttpServletRequest request, HttpSession session) {

		response.setCharacterEncoding("UTF-8");
		String[] s = arr.split(",");
		// for (String string : s) {
		// System.out.println(string);
		// }

		// System.out.println("projectName"+projectName+"description"+description);

		Projects p = new Projects();
		p.setProjectName(projectName);
		p.setProjectDescription(description);
		p.setTeamId(teamid);
		int a = teamManagerBiz.addProjectAndMember(p, managerSelect, s);
		// List<Projects> projectsList=null;
		// if(a>0){
		// projectsList=teamManagerBiz.getAllProjectsByTeamid(teamid);
		// }

		List<Projects> projectsList = teamManagerBiz.getAllProjectsByTeamid(teamid);

		PrintWriter out = null;
		try {
			out = response.getWriter();
			ObjectMapper mapper = new ObjectMapper();
			String data = mapper.writeValueAsString(projectsList);

			out.println(data);

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		out.close();
	}

	@RequestMapping("getAllTeamMeber.do")
	public void getAllTeamMeber(int teamid, HttpServletResponse response) {
		response.setCharacterEncoding("UTF-8");
		List<Users> teamUserList = teamManagerBiz.getAllTeamUserByTeamid(teamid);

		PrintWriter out = null;
		try {
			out = response.getWriter();
			ObjectMapper mapper = new ObjectMapper();
			String data = mapper.writeValueAsString(teamUserList);

			out.println(data);

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		out.close();
	}

	@RequestMapping("gotoProjectDetail.do")
	public String gotoProjectDetail(int projectid, int teamid, HttpServletRequest request, HttpSession session) {
		Users currentUser = (Users) session.getAttribute("currentUser");
		// 切换团队
		List<Map<String, String>> allTeam = teamManagerBiz.getAllTeamByUserid(currentUser.getUserId());
		// 申请加入团队模块
		List<Map<String, String>> applyPartList = teamManagerBiz.getPartApplyUsersByTeamid(teamid);
		List<Map<String, String>> listsize = teamManagerBiz.getApplyUsers1ByTeamid(teamid);
		if (listsize != null) {
			request.setAttribute("applyPartListSize", listsize.size());

		}

		List<Map<String, String>> projectMember = teamManagerBiz.getProjectMember(projectid);

		// 项目修改信息
		Projects project = teamManagerBiz.getProjectByProjectid(projectid);

		request.setAttribute("project", project);
		request.setAttribute("allTeam", allTeam);
		request.setAttribute("nowteamid", teamid);
		request.setAttribute("nowprojectid", projectid);
		request.setAttribute("applyPartList", applyPartList);

		request.setAttribute("projectMember", projectMember);
		return "projectdetail";
	}

	@RequestMapping("addProjectMember.do")
	public void addProjectMember(int projectid, int roleid, int userid, HttpServletResponse response,
			HttpSession session) {
		response.setCharacterEncoding("UTF-8");
		// System.out.println(projectid+"--"+roleid+"---"+userid);
		UserRoleProject memberUrp = new UserRoleProject();
		memberUrp.setRoleId(roleid);
		memberUrp.setProjectId(projectid);
		memberUrp.setUserId(userid);
		int c = teamManagerBiz.addProjectMember(memberUrp);

		List<Map<String, String>> projectMember = null;
		if (c > 0) {
			projectMember = teamManagerBiz.getProjectMember(projectid);
		}

		PrintWriter out = null;
		try {
			out = response.getWriter();
			ObjectMapper mapper = new ObjectMapper();
			String data = mapper.writeValueAsString(projectMember);

			out.println(data);

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		out.close();
	}

	@RequestMapping("updateProjectMember.do")
	public void updateProjectMember(int projectid, int urpid, String text, int type, HttpServletResponse response,
			HttpSession session) {
		response.setCharacterEncoding("UTF-8");
		System.out.println(projectid + "--" + 0 + "---" + urpid + "text" + text + "type" + type);
		int c = 0;
		if (("变更为项目经理").equals(text)) {
			c = teamManagerBiz.updateProjectMemberPTM(projectid, 0, urpid, type);
		}
		if (("变更为项目成员").equals(text)) {
			c = teamManagerBiz.updateProjectMemberMTP(projectid, 0, urpid);
		}

		List<Map<String, String>> projectMember = null;
		if (c > 0) {
			projectMember = teamManagerBiz.getProjectMember(projectid);
		}

		PrintWriter out = null;
		try {
			out = response.getWriter();
			ObjectMapper mapper = new ObjectMapper();
			String data = mapper.writeValueAsString(projectMember);

			out.println(data);

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		out.close();
	}

	@RequestMapping("deleteProjectMember.do")
	public void deleteProjectMember(int projectid, int urpid, HttpServletResponse response, HttpSession session) {
		response.setCharacterEncoding("UTF-8");
		System.out.println(projectid + "-----" + urpid);

		int c = teamManagerBiz.deleteProjectMember(urpid);
		List<Map<String, String>> projectMember = null;
		if (c > 0) {
			projectMember = teamManagerBiz.getProjectMember(projectid);
		}

		PrintWriter out = null;
		try {
			out = response.getWriter();
			ObjectMapper mapper = new ObjectMapper();
			String data = mapper.writeValueAsString(projectMember);

			out.println(data);

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		out.close();
	}

	@RequestMapping("checkPassword.do")
	public void checkPassword(String password, HttpServletResponse response, HttpSession session) {
		response.setCharacterEncoding("UTF-8");
		Users currentUser = (Users) session.getAttribute("currentUser");
		Users users = new Users();
		users.setUserName(currentUser.getUserName());
		users.setPassword(password);

		Users u = userBiz.login(users);
		PrintWriter out = null;
		try {
			out = response.getWriter();
			if (u != null) {
				out.println("ok");

			} else {
				out.println("no");
			}

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		out.close();
	}

	@RequestMapping("deleteProject.do")
	public String deleteProject(int projectid, int teamid, HttpServletRequest request) throws Exception {

		teamManagerBiz.deleteProjectByProjectid(projectid);
		return "redirect:/gotoProjectList.do?teamid=" + teamid;
	}

	@RequestMapping("updateProjectInfo.do")
	public String updateProjectInfo(int projectid, int teamid, String projectName, String description,
			HttpServletRequest request) throws Exception {

		System.out.println(projectName + description);
		Projects p = new Projects();
		p.setProjectId(projectid);
		p.setProjectName(projectName);
		p.setProjectDescription(description);
		teamManagerBiz.updateProjectInfoByProjectid(p);
		return "redirect:/gotoProjectDetail.do?projectid=" + projectid + "&teamid=" + teamid;
	}

	// xuyanjin

	@RequestMapping("getTeamByName.do")
	public String getTeamByName(String teamName, HttpServletRequest request) throws Exception {
		if (teamName != null && !teamName.equals("")) {
			List<Map<String, Object>> list = teamManagerBiz.getTeamByName(teamName);
			request.setAttribute("list", list);

			return "searchteamsec";
		} else {
			return "redirect:/getTeams.do";
		}
	}
	// @RequestMapping("getTeamByName.do")
	// public String getTeamByName(String teamName, HttpServletRequest request)
	// throws Exception {
	// int pageSize=4;
	// int currentPage=1;
	// String currPage=request.getParameter("currentPage");
	// if(currPage!=null){
	// currentPage=Integer.parseInt(currPage);
	// }
	// System.out.println("first"+currentPage);
	// System.out.println("first"+pageSize);
	// PageTeams pageteams =
	// teamManagerBiz.getTeamsec(teamName,currentPage,pageSize);
	// request.setAttribute("pageteams", pageteams);
	// return "searchteamsec";
	// }

	@RequestMapping("getTeams.do")
	public String getTeams(HttpServletRequest request) throws Exception {
		int pageSize = 4;
		int currentPage = 1;
		String currPage = request.getParameter("currentPage");
		if (currPage != null) {
			currentPage = Integer.parseInt(currPage);
		}
		System.out.println("first" + currentPage);
		System.out.println("first" + pageSize);
		PageTeams pageteams = teamManagerBiz.getTeams(currentPage, pageSize);
		request.setAttribute("pageteams", pageteams);
		return "searchteam";

	}

	// 这个可以注
	@RequestMapping("gotoTeamList.do")
	public String gotoTeamList(HttpServletRequest request, HttpSession session) throws Exception {
//
//		Map<String, Object> users = new HashMap<String, Object>();
//		users.put("userId", 1);
//		// User.put(userName, "����");
//		// User.put(password, "1111");
//		int userId = 1;
		Users currentUser = (Users) session.getAttribute("currentUser");
		List<Map<String, Object>> tlist = teamManagerBiz.gotoTeamList(currentUser.getUserId());
		request.setAttribute("tlist", tlist);

		return "teamlist";
	}

	@RequestMapping("addTeam.do")
	public String addTeam(String teamName, HttpSession session) throws Exception {
		Users currentUser = (Users) session.getAttribute("currentUser");
		if(teamName!=null&&!teamName.equals("")){
		System.out.println(teamName);
		Date createDate = new Date();
		System.out.println(createDate);
		// DateFormat df=new SimpleDateFormat("yyy-mm-dd");
		// String createDate = df.format(date);

		Teams teams = new Teams();
		teams.setCreateUserId(currentUser.getUserId());
		teams.setTeamName(teamName);
		teams.setCreateDate(createDate);
		teamManagerBiz.addTeam(teams);

		Teams teams1 = teamManagerBiz.selectTeam(teamName);
		int teamId1 = teams1.getTeamId();
		System.out.println(teamId1);
		UserTeam userteam = new UserTeam();
		userteam.setTeamId(teamId1);
		userteam.setUserId(currentUser.getUserId());
		userteam.setIsAccepted(1);
		userteam.setIsRemoved(0);
		teamManagerBiz.addUserTeam(userteam);
		}
		return "redirect:/gotoTeamList.do";
	}

	@RequestMapping("updateUsers.do")
	public String updateUsers(String userName, HttpSession session) throws Exception {
		Users currentUser = (Users) session.getAttribute("currentUser");
		if(userName!=null&&!userName.equals("")){
		System.out.println(userName);
		Users users = new Users();
		Date createDate = new Date();
		// int userId=333;
		users.setUserId(currentUser.getUserId());
		users.setUserName(userName);
		// users.setCreateDate(createDate);
		// users.setEmail("1212");
		// users.setPassword("13");
		// users.setTel("10");
		teamManagerBiz.updateUsers(users);
		return "updateinfosuccess";
		}else{
			return "userinfo";
		}
	}

	@RequestMapping("updateUserp.do")
	public void updateUserp(String lpassword, String password, HttpServletResponse response, HttpSession session) throws Exception {
		
		
		
		
		
		response.setCharacterEncoding("UTF-8");
		Users currentUser = (Users) session.getAttribute("currentUser");
		Users users = new Users();
		users.setUserName(currentUser.getUserName());
		users.setPassword(lpassword);

		Users u = userBiz.login(users);
		PrintWriter out = null;
		try {
			out = response.getWriter();
			if (u != null) {
				Users updateUser=new Users();
				updateUser.setUserId(currentUser.getUserId());
				updateUser.setPassword(password);
				teamManagerBiz.updateUserp(updateUser);
				out.println("true");

			} else {
				out.println("false");
			}

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		out.close();
		
		
		
		
	}

	 @RequestMapping("applyTeam.do")
	 public void applyTeam(int teamid,HttpServletResponse response,HttpSession session) throws Exception{
		response.setCharacterEncoding("UTF-8");
		PrintWriter out=response.getWriter();;
		System.out.println(teamid);
		Users currentUser=(Users)session.getAttribute("currentUser");
		UserTeam userTeam =teamManagerBiz.checkIsApplied(teamid, currentUser.getUserId());
		if(userTeam!=null){
		
		out.print("isApplied");
			
		}else{
		UserTeam ut=new UserTeam();
		ut.setUserId(currentUser.getUserId());
		ut.setTeamId(teamid);
		int a=teamManagerBiz.addApplyTeam(ut);
		
		if(a>0){
			out.println("ok");
			
		}else{
			out.println("no");
		}
		out.close();
		

		} 
	 }
	
	
	// jgh
	@RequestMapping("gotoUserinfo.do")
	public String gotoUserinfo(int teamid, HttpServletRequest request, HttpSession session) throws Exception {

		Users currentUser = (Users) session.getAttribute("currentUser");
		// 切换团队
		List<Map<String, String>> allTeam = teamManagerBiz.getAllTeamByUserid(currentUser.getUserId());
		// 申请加入团队模块
		List<Map<String, String>> applyPartList = teamManagerBiz.getPartApplyUsersByTeamid(teamid);
		List<Map<String, String>> listsize = teamManagerBiz.getApplyUsers1ByTeamid(teamid);
		if (listsize != null) {
			request.setAttribute("applyPartListSize", listsize.size());

		}

		request.setAttribute("allTeam", allTeam);
		request.setAttribute("nowteamid", teamid);
		request.setAttribute("applyPartList", applyPartList);

		return "userinfo";
	}

}
